<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    //创建对象的方式，自变量方式
    console.log('--------字面量方式----------');
    let obj = {
        name: '张三',
        sex: '男',
        job: '程序员',
        seyHi: function () {
            console.log(`${this.name}---${this.sex}---${this.job}`);
        }
    }
    obj.seyHi()
    //工厂模式创建对象
    console.log('---------------工厂模式创建对象--------------');
    function objnew(name, sex, job) {
        let obj = new Object()
        obj.name = name
        obj.sex = sex
        obj.job = job
        obj.seyHi = (function () {
            console.log(`${this.name}---${this.sex}---${this.job}`);
        })
        return obj
    }
    let objww = objnew('张三', '男', '程序员');
    let objzs = objnew('赵四', '女', 'yue你仙人');
    console.log(objww);
    console.log(objzs);
    console.log('--------------构造函数方式创建对象----------------');
    function Person(name, sex, job) {
        this.name = name
        this.sex = sex
        this.job = job
        this.seyHi = function () {
            console.log(`${this.name}---${this.sex}---${this.job}`);
        }
    }
    let objPerson = new Person('杨硕', '男', '卖唱的')
    console.log(objPerson);
    objPerson.seyHi()
    function Name(name, sex, job) {
        this.name = name
        this.sex = sex
        this.job =
            this.seyHi = function () {
                console.log(`${this.name}---${this.sex}---${this.job}`);
            }
    }
    let Str = new Person('周鑫', '男', '卖艺')
    console.log(Str);
    Str.seyHi()
    console.log('-----------原型方式创建对象-------------');
    function objPrto() {
        objPrto.prototype.name = '余日天天'
        objPrto.prototype.sex = '男'
        objPrto.prototype.job = '代码'
        objPrto.prototype.seyHi = function () {
            console.log(`${this.name}---${this.sex}---${this.job}`);
        }
    }
    let objPrtoback = new objPrto
    console.log(objPrtoback);
    objPrtoback.seyHi()
    // objPrtoback.seyHi()
    console.log('-------原型和字面量方式创建对象---------');
    function objPrtoNew() { }
    objPrtoNew.prototype = {
        name: '张三',
        sex: '男',
        job: '程序员',
        seyHi: function () {
            console.log(`${this.name}---${this.sex}---${this.job}`);
        }
    }
    //实例化
    let newBaclObj = new objPrtoNew()
    console.log(newBaclObj);
    newBaclObj.seyHi()
    function objName(params) { }
    objName.prototype = {
        name: '张三',
        sex: '男',
        job: '程序员',
        seyHi: function () {
            console.log(`${this.name}---${this.sex}---${this.job}`);
        }
    }
    let newobj = new objName()
    console.log(newobj);
    newobj.seyHi()
    console.log('-----原型加构造函数--------');
    function ObjPerson(name, sex, job) {
        this.name = name
        this.sex = sex
        this.job = job
        this.seyHi = function () {
            console.log(`${this.name}---${this.sex}---${this.job}`);
        }
    }
    ObjPerson.prototype = {
        seyHiTwo: function () {
            console.log(`${this.name}++${this.sex}+${this.job}`);
        }
    }
    let newObjPreson = new ObjPerson('周星驰', '男', '喜剧演员')
    console.log(newObjPreson);
    newObjPreson.seyHi()
    newObjPreson.seyHiTwo()
</script>